<?php

/**
 * Object/Tache.php
 */

namespace RHX\Model\Object;

use Zend\Db\Adapter\Adapter;

class Tache {

    public $id;
    public $action_id;
    public $date_effet;
    public $etat;
    public $param;
    protected $adapter;
    protected $table = null;

    const INACHEVEE	 = 0;
    const TERMINEE	 = 1;
    const EN_COURS	 = 2;

    public function __construct(Adapter $adapter, $data = array()) {
	$this->adapter = $adapter;
	$this->exchangeArray($data);
    }

    public function exchangeArray($data = array()) {
	$this->id		 = isset($data['id']) ? (int) $data['id'] : null;
	$this->action_id	 = isset($data['action_id']) ? (int) $data['action_id'] : 0;
	$this->date_effet	 = isset($data['date_effet']) ? $data['date_effet'] : date('Y-m-d');
	$this->etat		 = isset($data['etat']) ? $data['etat'] : self::INACHEVEE;
	$this->param		 = isset($data['param']) ? unserialize($data['param']) : array();
    }

    /**
     * Adapteur de base de données
     * 
     * @return Adapter
     */
    public function getAdapter() {
	return $this->adapter;
    }

    /**
     * Récupérer la table action
     * 
     * @return \RHX\Model\Table\ActionTable
     */
    public function getTable() {
	if (is_null($this->table)) {
	    $this->table = new \RHX\Model\Table\ActionTable($this->getAdapter());
	}

	return $this->table;
    }

    /**
     * Récupérer une action
     *
     * @return \RHX\Model\Object\Action
     */
    public function getAction() {
	// table action
	$tableAction	 = $this->getTable();
	$action		 = null;
	try {
	    $action = $tableAction->select(array('id' => $this->action_id))
		    ->current();
	    if (!$action) {
		$action = new Action();
	    }
	}
	catch (\Exception $ex) {
	    $action = new Action();
	}

	return $action;
    }

    public function execute() {
	$action = $this->getAction();
    }

}

?>
